package com;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.common.constant.SharesConstan;
import com.common.utils.DateUtil;
import com.common.utils.HttpClient5Utils;
import com.common.utils.MeUtils;
import com.common.utils.StringUtil;
import com.entity.*;
import com.service.*;
import com.vo.SharesTimeVo;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.*;

@SpringBootTest
@RunWith(SpringRunner.class)
public class SharesDataDemo {

    @Autowired
    private SharesDetailService sharesDetailService;

    @Autowired
    private SharesDataService sharesDataService;

    @Autowired
    private CodeCjlService codeCjlService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private HintCodeService hintCodeService;

    @Autowired
    private ShareHolderService shareHolderService;

    /**
     * 获取5分钟的数据
     */
    @Test
    public void getM5Data(){
        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",66);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);
            if(substring.startsWith("688")){
                continue;
            }
            if(name.contains("st")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){
              url=  "http://17.push2his.eastmoney.com/api/qt/stock/kline/get" +
                      "?cb=jQuery112407991803491462504_1636097949492" +
                      "&secid=0." +substring +
                      "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                      "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=5&fqt" +
                      "=0&end=20500101&lmt=1000000&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url=  "http://17.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112407991803491462504_1636097949492" +
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=5&fqt" +
                        "=0&end=20500101&lmt=1000000&_="+new Date().getTime();

            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.M5,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    sharesDataService.insertBatch(sharesDatas);
                }
            }catch (Exception e){

            }
        }
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     *
     */
    @Test
    public void cjlAndzdf(){

        Wrapper<SharesData> wr=new EntityWrapper<>();
        List<SharesData> sharesDataList = sharesDataService.selectList(wr);

        Map<String,List<SharesData>> map=new HashMap<>();
        for (SharesData sharesData : sharesDataList) {

        }

        for (String key : map.keySet()) {
            List<SharesData> sharesDatas = map.get(key);

            if(CollectionUtils.isEmpty(sharesDatas)){
                continue;
            }

            long cjlTotal=0L;
            for (SharesData sharesData : sharesDatas) {
                String cjl = sharesData.getCjl();
                cjlTotal=cjlTotal+ Long.valueOf(cjl);
            }

        }

    }

    /**
     *  //周最高涨幅超过百分之30的
     *  //成交量，涨幅的关系
     *  //找到成交量翻倍的股
     *  //找到涨幅区间，以周为单位，5个交易日，2周单位
     *  //往前推理启动的时候
     *  //和启动当天
     */
    @Test
    public void getzzf(){
        //计算往后5个交易日的最高涨幅
        //计算往后10个交易日的最高涨幅

        Wrapper<SharesData> wr=new EntityWrapper<>();
        List<SharesData> sharesData = sharesDataService.selectList(wr);

        Map<String,List<SharesData>> map=new HashMap<>();

        for (SharesData sharesDatum : sharesData) {

        }

        //计算区间涨幅

    }

    /**
     * 获取月线
     */


    //分成多少分。
    //+-+-----
    //昨天，前天的
    //后续多少天的区间最高，最低
    //回撤

    /**
     * 获取每隔月涨幅的涨幅
     */
    @Test
    public void getMzf(){
        Wrapper<SharesData> wr=new EntityWrapper<>();
        List<SharesData> sharesData = sharesDataService.selectList(wr);

        for (SharesData sharesDatum : sharesData) {
            BigDecimal kPrice = sharesDatum.getKPrice();
            BigDecimal cPrice = sharesDatum.getCPrice();
            //计算涨幅
        }
    }

    /**
     * 获取每周涨幅的振幅。
     */
    @Test
    public void getZzf(){
        Wrapper<SharesData> wr=new EntityWrapper<>();
        List<SharesData> sharesData = sharesDataService.selectList(wr);

        for (SharesData sharesDatum : sharesData) {
            BigDecimal kPrice = sharesDatum.getKPrice();
            BigDecimal cPrice = sharesDatum.getCPrice();
            //计算涨幅

        }
    }

    /**
     * 周线
     */
    @Test
    public void getz(){


        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            System.out.println(szorsh);
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);
            System.out.println(szorsh+"="+sharesCode.getId());
            String url="";
            if(szorsh.contains("sz")){
                url="http://28.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865152" +
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=102&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();

            }

            if(szorsh.contains("sh")){
                url="http://28.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865152" +
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=102&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.WEEK,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    sharesDataService.insertBatch(sharesDatas);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }


    /**
     * 月线
     */
    @Test
    public void gety(){
        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);

            System.out.println(szorsh+"="+sharesCode.getId());
            if(substring.startsWith("688")){
                continue;
            }
            if(name.contains("st")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){
                url="http://27.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865148" +
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=103&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://27.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865148" +
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=103&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.MONTH,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    sharesDataService.insertBatch(sharesDatas);
                }
            }catch (Exception e){
            e.printStackTrace();
            }
        }
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     * 日k数据
     */
    @Test
    public void getddata(){
        Wrapper<SharesDetail> wr=new EntityWrapper<>();
        wr.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wr);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);

            System.out.println(szorsh+"="+sharesCode.getId());
            if(substring.startsWith("688")){
                continue;
            }
            if(name.contains("st")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();

            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.DAY,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    List<SharesTimeVo> sharesTimeVos=new ArrayList<>();
                    //记录下来当天的时间，和明天昨天的时间
                    for (int i=0;i<sharesDatas.size()-1;i++){
                        if(DateUtil.compareDate("2021-09-15",sharesDatas.get(i).getTime())){
                            //判断最高涨幅是否大于百分之5
                            if(MeUtils.calculateTrend(sharesDatas.get(i).getHPrice().toString()
                                    ,sharesDatas.get(i).getKPrice().toString())
                                    .compareTo(new BigDecimal(0.05))==1){
                                SharesTimeVo sharesTimeVo = new SharesTimeVo();

                                sharesTimeVo.setJtime(sharesDatas.get(i).getTime());
                                BigDecimal jbig = MeUtils.calculateTrend(sharesDatas.get(i).getCPrice().toString()
                                        , sharesDatas.get(i).getKPrice().toString());
                                sharesTimeVo.setJzf(jbig.toString());

                                if(i!=0){
                                    SharesData sharesData = sharesDatas.get(i - 1);
                                    sharesTimeVo.setZtime(sharesDatas.get(i-1).getTime());
                                    BigDecimal zbig = MeUtils.calculateTrend(sharesData.getCPrice().toString()
                                            , sharesData.getKPrice().toString());
                                    sharesTimeVo.setZzj(zbig.toString());
                                }
                                if(i<sharesDatas.size()-2){
                                    SharesData sharesData = sharesDatas.get(i + 1);
                                    BigDecimal mbig = MeUtils.calculateTrend(sharesData.getCPrice().toString()
                                            , sharesData.getKPrice().toString());

                                    sharesTimeVo.setMtime(sharesDatas.get(i+1).getTime());
                                    sharesTimeVo.setMzf(mbig.toString());
                                }
                                sharesTimeVos.add(sharesTimeVo);
                            }
                        }
                    }
                    if(!CollectionUtils.isEmpty(sharesTimeVos)){
                        sharesCode.setZftime(JSONArray.toJSONString(sharesTimeVos));
                        sharesDetailService.updateById(sharesCode);
                    }

                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    /**
     * 保存前一天5分钟走势
     * 和当天5分钟走势
     */
    @Test
    public void getm5zf(){
        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wr=new EntityWrapper<>();
        wr.eq("status",66);
        wr.isNotNull("zftime");
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wr);

            for (SharesDetail sharesCode : sharesDetails) {

                String zftime = sharesCode.getZftime();
                List<SharesTimeVo> sharesTimeVos = JSONArray.parseArray(zftime, SharesTimeVo.class);
                Set<String>  times=new HashSet<>();
                for (SharesTimeVo sharesTimeVo : sharesTimeVos) {
                    times.add(sharesTimeVo.getJtime());
                    times.add(sharesTimeVo.getMtime());
                    times.add(sharesTimeVo.getZtime());
                }

                String szorsh = sharesCode.getCode();
                String name = sharesCode.getName();
                String substring = szorsh.substring(2);
                System.out.println(szorsh+"="+sharesCode.getId());
                if(substring.startsWith("688")){
                    continue;
                }
                if(name.contains("st")){
                    continue;
                }
                String url="";
                if(szorsh.contains("sz")){
                    url=  "http://17.push2his.eastmoney.com/api/qt/stock/kline/get" +
                            "?cb=jQuery112407991803491462504_1636097949492" +
                            "&secid=0." +substring +
                            "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                            "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=5&fqt" +
                            "=0&end=20500101&lmt=1000000&_="+new Date().getTime();
                }

                if(szorsh.contains("sh")){
                    url=  "http://17.push2his.eastmoney.com/api/qt/stock/kline/get" +
                            "?cb=jQuery112407991803491462504_1636097949492" +
                            "&secid=1." +substring +
                            "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                            "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=5&fqt" +
                            "=0&end=20500101&lmt=1000000&_="+new Date().getTime();

                }

                try{
                    HttpGet get=new HttpGet(url);
                    CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                    String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                    int rIndex = result.indexOf("(");
                    String resultStr = result.substring(rIndex + 1, result.length() - 2);
                    JSONObject datas2 = JSONObject.parseObject(resultStr);
                    String data = datas2.getString("data");
                    String klines = JSONObject.parseObject(data).getString("klines");
                    List<Object> parse = (List<Object>) JSON.parse(klines);
                    List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.M5,"");

                    if(!CollectionUtils.isEmpty(sharesDatas)){
                        List<SharesData> savelist=new ArrayList<>();
                        for (SharesData sharesData : sharesDatas) {
                            for (String time : times) {
                                if(sharesData.getTime().startsWith(time)){
                                    savelist.add(sharesData);
                                }
                            }
                        }
                        sharesDataService.insertBatch(savelist);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            long en = System.currentTimeMillis();
            long l = (en - st)/1000;
            System.out.println(l);

    }

    /**
     * 上周收盘价
     */
    @Test
    public void getzKprice(){


        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);
            if(substring.startsWith("688")){
                continue;
            }
            System.out.println(szorsh+"="+sharesCode.getId());
            if(name.contains("st")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){
                url="http://28.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865152" +
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=102&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();

            }

            if(szorsh.contains("sh")){
                url="http://28.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865152" +
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=102&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.WEEK,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    SharesData sharesData = sharesDatas.get(sharesDatas.size() - 1);
                    BigDecimal kPrice = sharesData.getCPrice();
                    sharesCode.setZkPrice(kPrice.toString());
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        sharesDetailService.updateBatchById(sharesDetails);
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     * 月开盘价
     */
    @Test
    public void getyKprice(){
        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);

            System.out.println(szorsh+"="+sharesCode.getId());
            if(substring.startsWith("688")){
                continue;
            }
            if(name.contains("st")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){
                url="http://27.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865148" +
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=103&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://27.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_1636098865148" +
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=103&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=sharesDataService.saveCjl(parse,szorsh,name, SharesConstan.MONTH,"");
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    SharesData sharesData = sharesDatas.get(sharesDatas.size() - 2);
                    BigDecimal kPrice = sharesData.getCPrice();
                    sharesCode.setYkPrice(kPrice.toString());
//                    sharesDetailService.updateById(sharesCode);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        sharesDetailService.updateBatchById(sharesDetails);
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     * 保存股东数据
     */
    @Test
    public void getgd() throws Exception{

        Wrapper<SharesDetail> wr=new EntityWrapper<>();
        wr.eq("status",66);
        wr.gt("id",21814);
        wr.orderBy("id");
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wr);

        for (SharesDetail sharesDetail : sharesDetails) {
            String code = sharesDetail.getCode();

            System.out.println(code+"==="+sharesDetail.getId());
            if(code.contains("688")){
                continue;
            }
            if(code.contains("689")){
                continue;
            }
            List<ShareHolder> shareHolders=new ArrayList<>();
            List<String> timeList=new ArrayList<>();
            timeList.add("2021-09-30");
            timeList.add("2021-06-30");
            timeList.add("2021-03-31");
            timeList.add("2020-12-31");
            timeList.add("2020-09-30");

            for (String time : timeList) {
                try {
                    String url="http://emweb.securities.eastmoney.com/PC_HSF10/ShareholderResearch/PageSDGD" +
                            "?code="+code+"&date="+time;
                    HttpGet httpGet=new HttpGet(url);
                    CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(httpGet);
                    String result = EntityUtils.toString(execute.getEntity(), "UTF-8");

                    JSONObject datas2 = JSONObject.parseObject(result);
                    String data = datas2.getString("sdgd");
                    List<Object> parse = (List<Object>) JSON.parse(data);
                    if(CollectionUtils.isEmpty(parse)){
                        continue;
                    }
                    for (Object o : parse) {
                        String endtime = JSONObject.parseObject(o.toString()).getString("END_DATE");
                        String name = JSONObject.parseObject(o.toString()).getString("HOLDER_NAME");
                        String num = JSONObject.parseObject(o.toString()).getString("HOLD_NUM");
                        String zb = JSONObject.parseObject(o.toString()).getString("HOLD_NUM_RATIO");
                        String change = JSONObject.parseObject(o.toString()).getString("HOLD_NUM_CHANGE");
                        ShareHolder shareHolder = new ShareHolder();
                        shareHolder.setChange(change);
                        shareHolder.setCode(code);
                        shareHolder.setZb(zb);
                        shareHolder.setName(name);
                        shareHolder.setNum(num);
                        shareHolder.setTime(endtime);

                        shareHolders.add(shareHolder);
                    }
                }catch (Exception e){
                    System.out.println(code);
                    e.printStackTrace();
                }

            }

            if(!CollectionUtils.isEmpty(shareHolders)){
                shareHolderService.insertBatch(shareHolders);
            }
        }
    }

    /**
     * 计算当天的涨幅
     */
    @Test
    public void getzfd(){
        Wrapper<HintCode> wr=new EntityWrapper<>();
        List<HintCode> hintCodes = hintCodeService.selectList(wr);

        for (HintCode hintCode : hintCodes) {
            String szorsh = hintCode.getCode();
            System.out.println(szorsh);
            String substring = szorsh.substring(2);
            String url="";
            if(szorsh.contains("sz")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();

            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
//                CodeCjl codeCjl=codeCjlService.saveCjl(parse,szorsh,name);
                String zdf=hintCodeService.getzf(parse,szorsh,hintCode);
                if(!StringUtil.isEmpty(zdf)){
                    hintCode.setZf(new BigDecimal(zdf));
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        hintCodeService.updateBatchById(hintCodes);
    }

    /**
     * 最近质押价格
     */
    //http://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery112306878483866223977_1637220767804&sortColumns=TRADE_DATE&sortTypes=-1&pageSize=50&pageNumber=1&reportName=RPT_CSDC_LIST&columns=ALL&quoteColumns=&source=WEB&client=WEB&filter=(SECURITY_CODE%3D%22300487%22)
    @Test
    public void getzyprice(){

        Wrapper<SharesDetail> wr=new EntityWrapper<>();
        wr.eq("status",66);
        wr.orderBy("id");
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wr);

        for (SharesDetail hintCode : sharesDetails) {
            String szorsh = hintCode.getCode();
            System.out.println(szorsh);
            String substring = szorsh.substring(2);
            String url="";
            if(szorsh.contains("sz")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=0." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();

            }

            url="http://datacenter-web.eastmoney.com/api/data/v1/get" +
                    "?callback=jQuery112306878483866223977_="+new Date().getTime()+
                    "&sortColumns=TRADE_DATE&sortTypes=-1&pageSize=50&pageNumber=1" +
                    "&reportName=RPT_CSDC_LIST&columns=ALL&quoteColumns=&source=WEB" +
                    "&client=WEB&filter=(SECURITY_CODE%3D%22" +
                    substring +
                    "%22)";

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
//                int rIndex = result.indexOf("(");
//                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(result);
                String data = datas2.getString("result");
                String klines = JSONObject.parseObject(data).getString("data");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                if(!CollectionUtils.isEmpty(parse)){
                    String zup = parse.get(0).toString();
                    String zytime = JSONObject.parseObject(zup).getString("TRADE_DATE");
                    String zyprice = JSONObject.parseObject(zup).getString("PLEDGE_MARKET_CAP");
                    String zynum = JSONObject.parseObject(zup).getString("REPURCHASE_BALANCE");
                    BigDecimal divide = new BigDecimal(zyprice).divide(new BigDecimal(zynum), 2, BigDecimal.ROUND_HALF_UP);
                    System.out.println(zytime + "=" + divide);
                    hintCode.setZyprice(zytime+"="+divide);
                }

            }catch (Exception e){
                e.printStackTrace();
            }
        }

        sharesDetailService.updateBatchById(sharesDetails);
    }


    @Test
    public void getzzd(){
//        shareHolderService.getgggg();
        shareHolderService.gethyssl();
    }



}
